# 圖表記錄間函數的範例

## top 函數範例

這些範例使用 top 函數，不過也同樣適用於 bottom、first 和 last 函數。不過請注意，first 和 last 函數僅與樞紐分析表有關。

範例 1:

研究以下描述在一維表格中使用 top 函數的連續表：

![Example table image of one dimensional straight table with top function](https://help.qlik.com/zh-TW/qlikview/September2025/Subsystems/Client/Content/Resources/Images/ui_gen_InterRecord4.png)

範例表格：具有 toptop 函數的一維連續表

| Month | sum(Val) | top(sum(Val)) | sum(Val) / top(sum(Val)) |
| --- | --- | --- | --- |
| - | 21 | 3 | 700% |
| 1 | 3 | 3 | 100% |
| 2 | 7 | 3 | 233% |
| 3 | 11 | 3 | 367% |

若是單一維度，top 函數將一律參考表格的第一個資料列 (不包含總計列)。

請注意，使用 top 函數的運算式也會在總計列中適當評估，因為總計與特定資料行區段有明確的關係，在本例中是與整個資料行有明確關係。

範例 2:

以下是主要按照 Grp 欄位排序的二維連續表。

![Example table image of two dimensional straight table with total qualifier](https://help.qlik.com/zh-TW/qlikview/September2025/Subsystems/Client/Content/Resources/Images/ui_gen_InterRecord6.png)

範例表格：具有 total total 限定詞的二維連續表

| Month | Grp | sum(Val) | top(sum(Val)) | top(total sum(Val)) |
| --- | --- | --- | --- | --- |
| - | - | 21 | - | 1 |
| 1 | A | 1 | 1 | 1 |
| 2 | A | 3 | 1 | 1 |
| 3 | A | 5 | 1 | 1 |
| 1 | B | 2 | 2 | 1 |
| 2 | B | 4 | 2 | 1 |
| 3 | B | 6 | 2 | 1 |

不含 total 限定詞的 top 函數現在會傳回按照最內部的排序群組 (在本例中為 Grp 維度) 中的頂端列評估的運算式。對於 Grp = A 將傳回一個值，對於 Grp = B 將傳回另一個值。

在多維表格中使用 total 限定詞之後，您可以再次參考對於所有列傳回相同值之表格的絕對頂端列。對於跨越整個資料行的資料行區段，當然會評估運算式。

使用 top 函數而沒有 total 限定詞的運算式將在總計列中評估為 NULL，因為它無法與特定資料行區段產生明確關聯。

我們現在會將以上的連續表轉換為啟動所有總計的樞紐分析表。

![Example table image of two dimensional pivot table with total qualifier](https://help.qlik.com/zh-TW/qlikview/September2025/Subsystems/Client/Content/Resources/Images/ui_gen_InterRecord7.png)

範例表格：具有 total total 限定詞的二維樞紐分析表

| Month | Grp | sum(Val) | top(sum(Val)) | top(total sum(Val)) |
| --- | --- | --- | --- | --- |
| 1 | A | 1 | 1 | 1 |
| 1 | B | 2 | 1 | 1 |
| 1 | 總計 | 3 | 1 | - |
| 2 | A | 3 | 3 | 1 |
| 2 | B | 4 | 3 | 1 |
| 2 | 總計 | 7 | 3 | - |
| 3 | A | 5 | 5 | 1 |
| 3 | B | 6 | 5 | 1 |
| 3 | 總計 | 11 | 5 | - |
| 總計 | - | 21 | - | 1 |

使用 top 函數而沒有 total 限定詞的運算式將在總計列中評估為 NULL，因為它無法與特定資料行區段產生明確關聯。不過，對於各個資料行區段，將評估所有部份加總。

使用 total 限定詞的運算式將缺少部份總計的值，但是將傳回總計列的值。

範例 3:

研究下列按照 Grp 欄位排序的連續表：

![Example table image of Two dimensional straight table sorted by Grp](https://help.qlik.com/zh-TW/qlikview/September2025/Subsystems/Client/Content/Resources/Images/ui_gen_InterRecord8.png)

範例表格：依 GrpGrp 排序的二維連續表

| Month | Grp | sum(Val) | top(sum(Val)) | sum(Val) / top(sum(Val)) |
| --- | --- | --- | --- | --- |
| - | - | 21 | - | - |
| 1 | A | 1 | 1 | 100% |
| 2 | A | 3 | 1 | 300% |
| 3 | A | 5 | 1 | 500% |
| 1 | B | 2 | 2 | 100% |
| 2 | B | 4 | 2 | 200% |
| 3 | B | 6 | 2 | 300% |

我們可以繼續變更內部欄位排序順序，以便圖表主要按照 Month (月份) 欄位排序。表格現在將如下所示：

![Example table image of Two dimensional straight table sorted by Month](https://help.qlik.com/zh-TW/qlikview/September2025/Subsystems/Client/Content/Resources/Images/ui_gen_InterRecord9.png)

範例表格：依 MonthMonth 排序的二維連續表

| Month | Grp | sum(Val) | top(sum(Val)) | sum(Val) / top(sum(Val)) |
| --- | --- | --- | --- | --- |
| - | - | 21 | - | - |
| 1 | A | 1 | 1 | 100% |
| 1 | B | 2 | 1 | 200% |
| 2 | A | 3 | 3 | 100% |
| 2 | B | 4 | 3 | 133% |
| 3 | A | 5 | 5 | 100% |
| 3 | B | 6 | 5 | 120% |

## above 函數範例

這些範例使用 above 函數，不過也同樣適用於 below、before 和 after 函數。不過請注意，before 和 after 函數僅與樞紐分析表有關。

範例 4:

研究以下描述在一維表格中使用 above 函數的連續表：

![Example table image of one dimensional straight table with Above function](https://help.qlik.com/zh-TW/qlikview/September2025/Subsystems/Client/Content/Resources/Images/ui_gen_InterRecord11.png)

範例表格：具有 Above Above 函數的一維連續表

| Month | sum(Val) | above(sum(Val)) | sum(Val) / above(sum(Val)) |
| --- | --- | --- | --- |
| - | 21 | - | - |
| 1 | 3 | - | - |
| 2 | 7 | 3 | 233% |
| 3 | 11 | 7 | 157% |

第三個資料行顯示運算式 sum(Val) 評估目前列之上的一列，可透過比較第二個資料行之中 sum(val) 的值加以確認。above 函數會在第一列上傳回 NULL，因為其上沒有任何列可用來評估運算式。above 函數一律會在總計列上傳回 NULL。

第四個資料行示範此函數最常見的用法，也就是計算不同時間週期等項目的差異。

範例 5:

研究以下二維樞紐分析表：

![Example table image of two dimension pivot table and the effect of total qualifier](https://help.qlik.com/zh-TW/qlikview/September2025/Subsystems/Client/Content/Resources/Images/ui_gen_InterRecord12.png)

範例表格：具有 total total 限定詞的二維樞紐分析表

| Grp | Month | sum(Val) | above(sum(Val)) | above(total sum(Val)) |
| --- | --- | --- | --- | --- |
| A | 1 | 1 | - | - |
| A | 2 | 3 | 1 | 1 |
| A | 3 | 5 | 3 | 3 |
| A | 總計 | 9 | - | - |
| B | 1 | 2 | - | 5 |
| B | 2 | 4 | 2 | 2 |
| B | 3 | 6 | 4 | 4 |
| B | 總計 | 12 | - | - |
| 總計 | - | 21 | - | - |

沒有 total 限定詞 (第三個資料行) 的 above 函數只能在各個排序群組中產生作用。會在各個資料行區段的頂端列上傳回 NULL 值。

新增 total 限定詞 (第四個資料行) 時，會將整個資料行視為一個資料行區段。只有頂端列會傳回 NULL。所有總計列將予以忽略，並傳回 NULL。

## RowNo 與 NoOfRows 函數範例

此範例使用 RowNo 和 NoOfRows 函數，不過也同樣適用於 ColumnNo 和 NoOfColumns 函數。不過請注意，ColumnNo 和 NoOfColumns 函數僅與樞紐分析表有關。

範例 6:

研究以下二維樞紐分析表：

![Example table image of RowNo and NoOfRows functions](https://help.qlik.com/zh-TW/qlikview/September2025/Subsystems/Client/Content/Resources/Images/ui_gen_InterRecord5_564x227.png)

範例表格：RowNo RowNo 和 NoOfRows NoOfRows 函數

| Month | Grp | RowNo() | RowNo(total) | NoOfRows() | NoOfRows(total) |
| --- | --- | --- | --- | --- | --- |
| 1 | A | 1 | 1 | 2 | 6 |
| 1 | B | 2 | 2 | 2 | 6 |
| 1 | 總計 | 0 | - | 2 | - |
| 2 | A | 1 | 3 | 2 | 6 |
| 2 | B | 2 | 4 | 2 | 6 |
| 2 | 總計 | 0 | - | 2 | - |
| 3 | A | 1 | 5 | 2 | 6 |
| 3 | B | 2 | 6 | 2 | 6 |
| 3 | 總計 | 0 | - | 2 | - |
| 總計 | - | - | 0 | - | 6 |

* 資料行 3 RowNo 函數將傳回各個排序群組資料行區段中的列數。在小計列中，將傳回列數 0，因為這些總計明確屬於特定的資料行區段。在總計列中，將傳回 NULL。
* 資料行 4 藉由 total 限定詞，RowNo 函數將傳回整個資料行中的列數。在小計列中，將傳回 NULL 值。在總計列中，將傳回 0。
* 資料行 5 NoOfRows 函數將傳回各個排序群組資料行區段中的資料列數。在小計列中，將傳回與資料列中相同的數字。在總計列中，將傳回 NULL。
* 資料行 6 藉由 total 限定詞，NoOfRows 函數將傳回整個資料行中的資料列數，這與總計列傳回的數字相同。在小計列中，將傳回 NULL。